package run.newbug.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import run.newbug.jt.mapper.RightsMapper;
import run.newbug.jt.pojo.Rights;

import java.util.Iterator;
import java.util.List;
@Component
public class RightsServiceImpl implements RightsService{
    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> getAll() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Rights> rightsOne = rightsMapper.selectList(queryWrapper);
        for(Rights x : rightsOne){
            queryWrapper.clear();
            queryWrapper.eq("parent_id", x.getId());
            x.setChildren(rightsMapper.selectList(queryWrapper));
        }
        return rightsOne;
    }
}
